// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
import {MonsterInfo} from "./MonsterInfo"
const {ccclass, property} = cc._decorator;

@ccclass
export  class Monster extends cc.Component {

    @property(cc.Label)
    nickName: cc.Label = null;

    @property(cc.Label)
    lv: cc.Label = null;

    @property(cc.Label)
    hp: cc.Label = null;

    @property(cc.Label)
   atk: cc.Label = null;

    @property(cc.Label)
    defense: cc.Label = null;

    @property(cc.Sprite)
    iamge: cc.Sprite = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

   public initInfo(info:MonsterInfo){

       this.nickName.string=info.name;

       this.lv.string=info.lv;

       this.hp.string=info.hp;

       this.atk.string=info.atk;

       this.defense.string=info.defense;

       let image=this.iamge;

       cc.loader.loader(info.imageUrl,cc.SpriteFrame,(error,spriteFrame)=>{

        //如果载入资源不出错
        if(error===null){
            
            image.spriteFrame=spriteFrame;
        }
       })
   }
    // update (dt) {}
}
